{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "085c0ac5",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using backend: tensorflow.compat.v1\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From G:\\Anaconda3\\envs\\py3.8\\lib\\site-packages\\tensorflow\\python\\compat\\v2_compat.py:101: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "non-resource variables are not supported in the long term\n",
      "WARNING:tensorflow:From G:\\Anaconda3\\envs\\py3.8\\lib\\site-packages\\deepxde\\nn\\initializers.py:118: The name tf.keras.initializers.he_normal is deprecated. Please use tf.compat.v1.keras.initializers.he_normal instead.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "\"\"\"Backend supported: tensorflow.compat.v1, tensorflow, pytorch, jax\"\"\"\n",
    "import deepxde as dde\n",
    "import numpy as np\n",
    "from deepxde.backend import tf\n",
    "\n",
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c22ec555",
   "metadata": {},
   "source": [
    "## 函数数据生成\n",
    "\n",
    "https://deepxde.readthedocs.io/en/latest/modules/deepxde.geometry.html\n",
    "\n",
    "https://deepxde.readthedocs.io/en/latest/modules/deepxde.data.html"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e967eadb",
   "metadata": {},
   "source": [
    "一元函数$x\\in \\mathbb{R}$：$$y = x \\sin(5 x), \\,\\,\\,\\, x\\in [-1,1]$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "c8fa9919",
   "metadata": {},
   "outputs": [],
   "source": [
    "def func(x):\n",
    "    \"\"\"\n",
    "    x: array_like, N x D_in\n",
    "    y: array_like, N x D_out\n",
    "    \"\"\"\n",
    "    return x * np.sin(5 * x)\n",
    "\n",
    "geom = dde.geometry.Interval(-1, 1) # geom = dde.geometry.geometry_1d.Interval(-1,1)\n",
    "num_train = 16\n",
    "num_test = 100\n",
    "data = dde.data.Function(geom, func, num_train, num_test) # 均匀采样 np.linspace(-1, 1, num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "ff56d136",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 2)"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data.train_next_batch()), len(data.test())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "48ae6d51",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((16, 1), (16, 1))"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.train_next_batch()[0].shape, data.train_next_batch()[1].shape  # 参数 batch_size 并没有什么用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "c6a82c75",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((100, 1), (100, 1))"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.test()[0].shape, data.test()[1].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "062c484d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x2701d17c3a0>"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAVSklEQVR4nO3df4wc93n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+uPpdzPfCTwP6OyZ8CPkG7zk8A/wb4J0tY172ZORERNwPPRMQfV0cmi9bg+vpu2h/Mj2Xmd6rJi15fsxffZdrsfWWuNgPZzxbo8+0NI36UduD/vY7JjW/PPmt7gfbpyv9Vfb9yFNjc42sHWdeMnwD+R2Z2HnkPcp3NZ6D714oP/Bzs3Tpfi4gNmXmp+m/T5Sbqioh+lvsg8EJmvtax7LeGI+LfA19Yyroyc6J6vhwR/4X2fyf/kGVeXxGxjnbYfzYzj3Qse9Hra5Ze7uw6V5vre3jtYvV0x9mIeB/wBPBgZr4+M32e7bkktXX8w0xmHo+I34qIm3p57SDr6vC2/2EPeJ3NZ6D7VwmndOa7W+cxYHc1vBvo5X8MvehnuW87d1iF3owPAV2/0R9EXRHxzoh418ww8Pc7+l+29RURAXwGOJuZvz5rXlPrq5c7ux4Dfrb6NcU9wLer01CDvCvsgsuOiE3AEeDDmfn1junzbc+lqu091fYjIu6mnTuv9/LaQdZV1fO9wI/Qsc8twTqbz2D3r6a/hV7KB+0P90Xg/wKvASeq6RuB4x3tdtD+Vcc3aJ8Kmpn+fcBJ4Hz1fGNDdXVdbpe63kF7x//eWa//T8AZ4KVqo25Yqrpo/wrga9XjlZWyvmifoshqnbxYPXY0vb667SvAo8Cj1XAAn6zmn6Hj12Fz7WcNraOF6noC+FbHuhlbaHsuYW2PVX1/jfYXyh9YCeusGv854KlZrxvYOqN9cHcJuEI7uz6ylPuXV9pKUiFKOKUjScLAl6RiGPiSVAgDX5IKYeBLUiEMfEkqhIEvSYUw8CWpEP8PmZPcy1l2hVwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plt.figure(figsize = (5, 5))\n",
    "x,y = data.train_next_batch()\n",
    "# plt.plot(x, y)\n",
    "plt.scatter(x, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "0172c453",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x2701d29b2b0>"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAVSklEQVR4nO3df4wc93nf8ffTE4WcHScnRZRNnsRKAQjWamWXwkZRrCJxIrGU2CSkhRaQkjhM64AQEKV20RAhYSAIYLRUyjZIUzh2WFkt0xgRCpulCJcuI9ExgtawoKMoi1IYmrTzQ7xjxIvqs9P2UFHM0z92Tl2e9u52b2bv1/f9AhY7P74732dnZj8czu7MRWYiSVr7/sZyFyBJWhoGviQVwsCXpEIY+JJUCANfkgph4EtSIRoJ/Ih4ICLORcSFiNg3T7sfiIirEfEPm+hXktS72oEfEUPAJ4EHgTuARyLijjna/Rpwom6fkqT+NXGEfzdwITO/mZlvAE8BO7u0+0Xg88DlBvqUJPXpugaWMQq82jF+EfjBzgYRMQp8CPgx4Ad6XfBNN92Ut912WwMlSlIZTp069ZeZub7bvCYCP7pMm32/ht8Afjkzr0Z0a96xsIg9wB6ATZs2MTY21kCJklSGiPizueY1EfgXgVs7xm8BJma1aQFPVWF/E7AjIt7MzKOzF5aZh4BDAK1Wyxv9SFJDmgj854HNEXE7MA48DPxUZ4PMvH1mOCL+I/CFbmEvSRqc2oGfmW9GxGO0f30zBDyZma9ExKPV/E/X7UOSVF8TR/hk5nHg+KxpXYM+M3+uiT4lSf3xSltJKkQjR/haW46eHufgiXNMTE2zcWSYvdu3sGvr6HKXpRXO/WblM/B1jaOnx9l/5AzTV64CMD41zf4jZwAW/eE1CFamJrfLIPYbNc9TOrrGwRPn3vrQzpi+cpWDJ84t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YOqN9cHcJuEI7uz6ylPuXV9pKUiFKOKUjScLAl6RiGPiSVAgDX5IKYeBLUiEMfEkqhIEvSYUw8CWpEP8PmZPcy1l2hVwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "x_ = np.linspace(-1, 1, num_train)\n",
    "# x_ = np.linspace(-1, 1, num_test)\n",
    "y_ = func(x_)\n",
    "# plt.plot(x_, y_)\n",
    "plt.scatter(x_, y_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "2a40c177",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x2701d2353a0>"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD4CAYAAADvsV2wAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAb4ElEQVR4nO3dfbAc1Xnn8e8PIeJL4nDBCJAuaEWqKGyviS2vgknYSjBYa5CTSCbrDU7iKImrVFRC1lAJm+tyVSpV+QNlyZtT68SrYCfKJhXw2kSoDF4FhKnU4jXFBckGIQswdoyuFLghyN5dVGuBn/1jemA0TM/03O6e6Zffp+rWvHRP99F0n0dnnj7ntCICMzNrvlOmXQAzM5sMB3wzs5ZwwDczawkHfDOzlnDANzNriVOnXYBhzj777Fi3bt20i2FmVhuPPPLIP0fEqkHLKh3w161bx8LCwrSLYWZWG5L+MW1ZISkdSVdLOiTpaUnzQ9b7EUmvSPr3RezXzMyyyx3wJa0APgFcA7wV+KCkt6as93vAnrz7NDOz8RXRwr8UeDoinomI7wK3A5sHrPfrwOeA5wvYp5mZjamI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u+TvbJhSz682pHSGzce/G9iaPN8KZPnFkMU4231d7jAJel3vBwZe0S+jXJK+X9Ibu8+Bf9ez/6l9X5IEfAo4GBF/2LesqO8ry70bdgO/mPSmuAz4dpKGKvO+DyO3LWktcCfwoYh4suf9YcdzUmU7Lzl+SLqUTtx5IctnyyxXUp4zgJ+g55ybwHc2TLnnV9FXoSf5R6dyHwb+H/AcsCd5fw1wT896m+j06vg6nVRQ9/03AXuBp5LHswoq18DtDijX6XRO/DP6Pv/fgMeAryYHdfWkykWnF8BXkr8DVfm+6KQoIvlO9id/m4r+vgadK8D1wPXJcwGfSJY/Rk/vsLTzrKDvaFS5bgNe7PluFkYdzwmW7YZk31+hc0H5x6rwnSWvfwm4ve9zpX1ndBp3R4ETdGLXhyd5fnlqBTOzlmhDSsfMzHDANzNrDQd8M7OWcMA3M2sJB3wzs5ZwwDczawkHfDOzlvj/8PHozKT0WEYAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "test_x,test_y = data.test()\n",
    "# plt.plot(test_x,test_y)\n",
    "plt.scatter(test_x,test_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "53152e4f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "6b6ac1c5",
   "metadata": {},
   "source": [
    "二元函数$x\\in \\mathbb{R}^2$：$$y = (x_1+x_2)^2, x_i\\in [-1,1]$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "id": "abc8fb2d",
   "metadata": {},
   "outputs": [],
   "source": [
    "def func(x):\n",
    "    \"\"\"\n",
    "    x: array_like, N x D_in\n",
    "    y: array_like, N x D_out\n",
    "    \"\"\"\n",
    "    return (x[:,0]+x[:,1])*(x[:,0]+x[:,1])\n",
    "\n",
    "# geom = dde.geometry.geometry_2d.Disk(center=(0,0), radius=1)\n",
    "geom = dde.geometry.geometry_2d.Rectangle(xmin=(-1,-1), xmax=(1,1))\n",
    "# geom = dde.geometry.geometry_2d.Triangle((-1,-1), (-1,1), (1,0))\n",
    "# geom = dde.geometry.geometry_2d.Polygon(vertices=[(-1,-1), (1,-1), (3,0), (1,1), (-1,1)])\n",
    "num_train = 100\n",
    "num_test = 200\n",
    "data = dde.data.Function(geom, func, num_train, num_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "id": "b609949f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Warning: 200 points required, but 225 points sampled.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(2, 2)"
      ]
     },
     "execution_count": 160,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data.train_next_batch()), len(data.test())    # Warning，num_test变多了，这是由采样方法造成的差异"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "id": "64dbc549",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((100, 2), (100,))"
      ]
     },
     "execution_count": 161,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.train_next_batch()[0].shape, data.train_next_batch()[1].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "id": "41e56889",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((225, 2), (225,))"
      ]
     },
     "execution_count": 162,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.test()[0].shape, data.test()[1].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ab5ab91",
   "metadata": {},
   "outputs": [],
   "source": [
    "x,y = data.train_next_batch()\n",
    "# x,y = data.test()\n",
    "\n",
    "\n",
    "# plt.figure(figsize=(8,8))\n",
    "ax = plt.axes(projection='3d')\n",
    "# ax.plot3D(x[:,0], x[:,1],y)\n",
    "ax.scatter3D(x[:,0], x[:,1],y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8a0e3e6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "2febc459",
   "metadata": {},
   "source": [
    "三元函数$x\\in \\mathbb{R}^3$：$$y = (x_1+x_2+x_3)^2, x_i\\in [-1,1]$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "id": "d82398b5",
   "metadata": {},
   "outputs": [],
   "source": [
    "def func(x):\n",
    "    \"\"\"\n",
    "    x: array_like, N x D_in\n",
    "    y: array_like, N x D_out\n",
    "    \"\"\"\n",
    "    return tf.pow(tf.reduce_sum(x, axis=[1]),2)\n",
    "\n",
    "geom = dde.geometry.geometry_3d.Cuboid(xmin=(-1,-1,-1), xmax=(1,1,1))\n",
    "# geom = dde.geometry.geometry_3d.Sphere(center=(0,0,0), radius=2)\n",
    "\n",
    "num_train = 1000\n",
    "num_test = 800\n",
    "data = dde.data.Function(geom, func, num_train, num_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 193,
   "id": "1ce96245",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Warning: 800 points required, but 1000 points sampled.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(2, 2)"
      ]
     },
     "execution_count": 193,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data.train_next_batch()), len(data.test())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 194,
   "id": "5b2584c5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((1000, 3), TensorShape([1000]))"
      ]
     },
     "execution_count": 194,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.train_next_batch()[0].shape, data.train_next_batch()[1].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "id": "731a1dcd",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((1000, 3), TensorShape([1000]))"
      ]
     },
     "execution_count": 195,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.test()[0].shape, data.test()[1].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8a30a748",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "5fd056f0",
   "metadata": {},
   "source": [
    "n元函数$x\\in \\mathbb{R}^n$：$$y = (\\sum^n_{i=1}x_i)^2, x_i\\in [-1,1]$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "749d6dcc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Warning: Hypersphere.uniform_points not implemented. Use random_points instead.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "((100, 100000), TensorShape([100]))"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def func(x):\n",
    "    \"\"\"\n",
    "    x: array_like, N x D_in\n",
    "    y: array_like, N x D_out\n",
    "    \"\"\"\n",
    "    return tf.pow(tf.reduce_sum(x, axis=[1]),2)\n",
    "\n",
    "n = 100\n",
    "\n",
    "# geom = dde.geometry.geometry_nd.Hypercube(xmin=-np.ones(n), xmax=np.ones(n))  \n",
    "# Hypercube 的高维实现是否有问题  n<20出结果比较快，n>30就崩溃\n",
    "\n",
    "geom = dde.geometry.geometry_nd.Hypersphere(center=np.zeros(n), radius=np.sqrt(sum(np.ones(n))))\n",
    "\n",
    "num_train = 100\n",
    "num_test = 80\n",
    "data = dde.data.Function(geom, func, num_train, num_test)\n",
    "\n",
    "data.train_next_batch()[0].shape, data.train_next_batch()[1].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e6aea9fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Warning: Hypersphere.uniform_points not implemented. Use random_points instead.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(2, 2)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data.train_next_batch()), len(data.test())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "10c74cd6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((100, 1000), TensorShape([100]))"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.train_next_batch()[0].shape, data.train_next_batch()[1].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "id": "2f9ffce4",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((800, 100), TensorShape([800]))"
      ]
     },
     "execution_count": 218,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.test()[0].shape, data.test()[1].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25dbdadf",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "6378b947",
   "metadata": {},
   "source": [
    "## 偏微分方程数据生成"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a3284d4",
   "metadata": {},
   "source": [
    "一维描述：\n",
    "\n",
    "https://deepxde.readthedocs.io/en/latest/demos/pinn_forward/poisson.1d.dirichletperiodic.html\n",
    "\n",
    "We will solve a Poisson equation 我们将求解一个泊松方程:\n",
    "$$\\large -\\Delta u = \\pi^2 \\sin(\\pi x), x \\in [-1,1]$$\n",
    "\n",
    "with the Dirichlet boundary conditions 与狄利克雷边界条件:$\\large u(-1) = 0, u(1) = 0$\n",
    "\n",
    "The exact solution is 精确解: $\\large u(x) = \\sin(\\pi x)$.\n",
    "\n",
    "\n",
    "mathematica求解代码：\n",
    "```mathematica\n",
    "LaplaceEquation = -D[u[x], {x, 2}] == Pi^2 * Sin[Pi*x];\n",
    "DSolve[{LaplaceEquation, u[-1] == 0, u[1] == 0}, u[x], x]\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "2a028196",
   "metadata": {},
   "outputs": [],
   "source": [
    "def pde(x, y):\n",
    "    dy_xx = dde.grad.hessian(y, x)\n",
    "    return -dy_xx - np.pi ** 2 * tf.sin(np.pi * x)\n",
    "\n",
    "def boundary(x, on_boundary):\n",
    "    return on_boundary\n",
    "\n",
    "def func(x):\n",
    "    return np.sin(np.pi * x)\n",
    "\n",
    "\n",
    "geom = dde.geometry.Interval(-1, 1)\n",
    "bc = dde.icbc.DirichletBC(geom, func, boundary)\n",
    "data = dde.data.PDE(geom, pde, bc, 16, 2, solution=func, num_test=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "5e77ff68",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3, 3)"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data.train_next_batch()), len(data.test())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "8c99c39b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((20, 1), (20, 1), None)"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.train_next_batch()[0].shape, data.train_next_batch()[1].shape, data.train_next_batch()[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "4baca326",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Compiling model...\n",
      "Building feed-forward neural network...\n",
      "'build' took 0.050794 s\n",
      "\n",
      "'compile' took 0.401603 s\n",
      "\n",
      "Initializing variables...\n",
      "Training model...\n",
      "\n",
      "Step      Train loss              Test loss               Test metric   \n",
      "0         [4.65e+01, 3.65e-03]    [4.91e+01, 3.65e-03]    [9.61e-01]    \n",
      "1000      [1.19e-04, 2.91e-08]    [2.55e-04, 2.91e-08]    [7.37e-04]    \n",
      "\n",
      "Best model at step 1000:\n",
      "  train loss: 1.19e-04\n",
      "  test loss: 2.55e-04\n",
      "  test metric: [7.37e-04]\n",
      "\n",
      "'train' took 3.924833 s\n",
      "\n"
     ]
    }
   ],
   "source": [
    "layer_size = [1] + [50] * 3 + [1]\n",
    "activation = \"tanh\"\n",
    "initializer = \"Glorot uniform\"\n",
    "net = dde.nn.FNN(layer_size, activation, initializer)\n",
    "\n",
    "model = dde.Model(data, net)\n",
    "model.compile(\"adam\", lr=0.001, metrics=[\"l2 relative error\"])\n",
    "\n",
    "losshistory, train_state = model.train(epochs=1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77caaa5a",
   "metadata": {},
   "source": [
    "n维描述：\n",
    "\n",
    "We will solve a Poisson equation 我们将求解一个泊松方程:\n",
    "$$\\large -\\Delta u = -\\sum^n_{i=1} \\frac{\\partial^2 u}{\\partial x_i^2} = \\pi^2 \\sum^n_{i=1}\\sin(\\pi x_i), x_i \\in [-1,1]$$\n",
    "\n",
    "\n",
    "with the Dirichlet boundary conditions 与狄利克雷边界条件:$\\large u(x_i=-1) = 0, u(x_i=1) = 0$\n",
    "\n",
    "The exact solution is 精确解: $\\large u(\\boldsymbol{x}) = \\sum^n_{i=1}\\sin(\\pi x_i)$.\n",
    "\n",
    "mathematica求解代码：\n",
    "```mathematica\n",
    "LaplaceEquation = -D[u[x], {x, 2}] == Pi^2 * Sin[Pi*x];\n",
    "DSolve[{LaplaceEquation, u[-1] == 0, u[1] == 0}, u[x], x]\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "10fabb41",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using backend: tensorflow.compat.v1\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From G:\\Anaconda3\\envs\\py3.8\\lib\\site-packages\\tensorflow\\python\\compat\\v2_compat.py:101: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "non-resource variables are not supported in the long term\n",
      "WARNING:tensorflow:From G:\\Anaconda3\\envs\\py3.8\\lib\\site-packages\\deepxde\\nn\\initializers.py:118: The name tf.keras.initializers.he_normal is deprecated. Please use tf.compat.v1.keras.initializers.he_normal instead.\n",
      "\n",
      "Warning: Hypersphere.uniform_points not implemented. Use random_points instead.\n"
     ]
    }
   ],
   "source": [
    "import deepxde as dde\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from deepxde.backend import tf\n",
    "\n",
    "def pde(x, y):\n",
    "    dy_xx = dde.grad.hessian(y, x)\n",
    "    # Use tf.sin for backend tensorflow.compat.v1 or tensorflow\n",
    "    return -dy_xx - np.pi ** 2 * tf.reduce_sum(tf.sin(np.pi * x), axis=1)\n",
    "\n",
    "def boundary(x, on_boundary):\n",
    "    return on_boundary\n",
    "\n",
    "def func(x):\n",
    "    return np.add.reduce(np.sin(np.pi * x),axis=1,keepdims=True)\n",
    "\n",
    "\n",
    "n = 100 # train_distribution=\"pseudo\"\n",
    "# geom = dde.geometry.geometry_nd.Hypercube(xmin=-np.ones(n), xmax=np.ones(n)) \n",
    "geom = dde.geometry.geometry_nd.Hypersphere(center=np.zeros(n), radius=np.sqrt(sum(np.ones(n))))\n",
    "\n",
    "bc = dde.icbc.DirichletBC(geom, lambda x: 0, boundary)\n",
    "data = dde.data.PDE(geom, pde, bc, 100, 80, train_distribution=\"pseudo\", solution=func, num_test=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "eda6b29b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3, 3)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data.train_next_batch()), len(data.test())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e39d1c97",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((260, 100), (260, 1), None)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.train_next_batch()[0].shape, data.train_next_batch()[1].shape, data.train_next_batch()[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "178011cd",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Compiling model...\n",
      "Building feed-forward neural network...\n",
      "'build' took 0.115940 s\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "G:\\Anaconda3\\envs\\py3.8\\lib\\site-packages\\keras\\legacy_tf_layers\\core.py:236: UserWarning: `tf.layers.dense` is deprecated and will be removed in a future version. Please use `tf.keras.layers.Dense` instead.\n",
      "  warnings.warn('`tf.layers.dense` is deprecated and '\n",
      "G:\\Anaconda3\\envs\\py3.8\\lib\\site-packages\\keras\\engine\\base_layer_v1.py:1676: UserWarning: `layer.apply` is deprecated and will be removed in a future version. Please use `layer.__call__` method instead.\n",
      "  warnings.warn('`layer.apply` is deprecated and '\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "'compile' took 5.919905 s\n",
      "\n",
      "Initializing variables...\n",
      "Training model...\n",
      "\n",
      "Step      Train loss              Test loss               Test metric   \n",
      "0         [3.92e+03, 2.66e-01]    [4.31e+03, 2.66e-01]    [9.94e-01]    \n",
      "1000      [3.86e+03, 1.59e-11]    [4.33e+03, 1.59e-11]    [1.02e+00]    \n",
      "\n",
      "Best model at step 1000:\n",
      "  train loss: 3.86e+03\n",
      "  test loss: 4.33e+03\n",
      "  test metric: [1.02e+00]\n",
      "\n",
      "'train' took 7.291901 s\n",
      "\n"
     ]
    }
   ],
   "source": [
    "layer_size = [n] + [50] * 3 + [1]\n",
    "activation = \"tanh\"\n",
    "initializer = \"Glorot uniform\"\n",
    "net = dde.nn.FNN(layer_size, activation, initializer)\n",
    "\n",
    "model = dde.Model(data, net)\n",
    "model.compile(\"adam\", lr=0.001, metrics=[\"l2 relative error\"])\n",
    "\n",
    "losshistory, train_state = model.train(epochs=1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef6261b4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3a7744f3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "22930e39",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py3.8",
   "language": "python",
   "name": "py3.8"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
